<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加页面</title>
    <th:block th:include="material/core/resources::headers"/>
</head>

<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form" id="addAdminForm" name="addAdminForm">
            <div class="layui-form-item">
                <label for="num" class="layui-form-label">
                    <span class="x-red"></span>物料收入编号：
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="num" name="num" required="" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="id" class="layui-form-label">
                    <span class="x-red"></span>物料编号：
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="id" name="id" required=""
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="quantity" class="layui-form-label">
                    <span class="x-red"></span>收入数量：
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="quantity" name="quantity" required=""
                           autocomplete="off" class="layui-input">
                </div>
            </div>


            <div class="layui-form-item">
                <label for="date" class="layui-form-label">
                    <span class="x-red"></span>收入日期：
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="date" name="date" required=""
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="sender" class="layui-form-label">
                    <span class="x-red"></span>发送者：
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="sender" name="sender" required=""
                           autocomplete="off" class="layui-input">
                </div>
            </div><div class="layui-form-item">
            <label for="receiver" class="layui-form-label">
                <span class="x-red"></span>接受者：
            </label>
            <div class="layui-input-inline">
                <input type="text" id="receiver" name="receiver" required=""
                       autocomplete="off" class="layui-input">
            </div>
        </div>

            <div class="layui-form-item">
                <label for="remark" class="layui-form-label">
                    <span class="x-red"></span>备注：
                </label>
                <div class="layui-input-inline" style="width: 400px">
                    <textarea id="remark" style="display: none;"></textarea>
                </div>
            </div>
            <div class="layui-form-item" style="padding-left: 110px">
                <button class="layui-btn" lay-filter="insert" lay-submit="">
                    添加
                </button>
                <button class="layui-btn" type="reset">
                    重置
                </button>
            </div>

        </form>

    </div>
</div>

<script>
    layui.use(['form', 'layer','layedit'],
        function () {
            const $ = layui.jquery;
            const form = layui.form, layer = layui.layer;
            const layedit = layui.layedit;
            //创建一个编辑器
            const edi = layedit.build('remark');
            layedit.getContent(edi);
            layedit.sync(edi);
            layui.use('layedit', function(){
                var layedit = layui.layedit;
                layedit.build('demo'); //建立编辑器
            });



            // 目前认为 submit应与添加按钮绑定的 lay-filter="insert" 一致
            form.on('submit(insert)',
                //获取数据
                function () {
                    const a = $("#num").val();
                    const b = $("#id").val();
                    const c = $("#quantity").val();
                    const d = $("#date").val();
                    const e = $("#sender").val();
                    const f = $("#receiver").val();
                    const g = $("#remark").val();
                    const data = {
                        miId: a,
                        mId: b,
                        miQuantity: c,
                        miDate: d,
                        miSender: e,
                        miReceiver: f,
                        remark: g
                    };
                    $.ajax({
                        type: "POST",
                        url: "/mi/insert",
                        data: data,
                        async: true,
                        dataType: "json",
                        // 直接将后台的数据集 在此处定义
                        success: function (code) {
                            if (code.code === 1) {
                                layer.alert("增加成功", {
                                    icon: 6
                                }, function () {
                                    xadmin.close();
                                    xadmin.father_reload();
                                });
                                // if 执行完毕之前要 return false 防止跳转
                                return false;
                            } else if (code.code !== 1) {
                                layer.alert("添加失败", {
                                    icon: 7
                                }, function () {
                                    xadmin.close();
                                    xadmin.father_reload();
                                });
                                return false;
                            }
                        }
                    });
                    return false;
                });
        });
</script>

</body>

</html>